using TMPro;
using UnityEngine;
using UnityEngine.UI;

namespace Gj
{
    public class InputHelper : NodeHelper
    {
        public bool pro;
        private InputField _InputField;
        private TMP_InputField _InputFieldPro;

        private InputField InputField
        {
            get
            {
                if (_InputField == null) _InputField = GetComponent<InputField>();
                return _InputField;
            }
        }

        private TMP_InputField InputFieldPro
        {
            get
            {
                if (_InputFieldPro == null) _InputFieldPro = GetComponent<TMP_InputField>();
                return _InputFieldPro;
            }
        }

        protected override BindDataType bindDataType => BindDataType.String;

        protected override void Start()
        {
            if (pro)
                InputFieldPro.onValueChanged.AddListener(Change);
            else
                InputField.onValueChanged.AddListener(Change);
        }

        protected override void BindData(string s)
        {
            // if (InputField.text.Equals(s)) return;
            if (pro)
                InputFieldPro.text = s;
            else
                InputField.text = s;
        }
    }
}